//
//  SSTopBottomView.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/6/21.
//

import UIKit

class SSTopBottomView: UIView {
    
    var imageV = UIImageView()
    var titleLab = UILabel()
    
    

    override public init(frame: CGRect) {
        super.init(frame: frame)
        
        //整个控件的默认尺寸(和某宝上面的按钮同样大小)
        if frame.isEmpty {self.frame = CGRect(x: 0, y: 0, width: 110, height: 30)}
        setupUI()
        
    }
    
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
    
    func setupUI() {
        let imageV = UIImageView()
        addSubview(imageV)
        self.imageV = imageV
        
        let titleLab = UILabel()
        titleLab.font = UIFont.systemFont(ofSize: 14)
        titleLab.textAlignment = .center
        addSubview(titleLab)
        self.titleLab = titleLab
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let imageVH:CGFloat = imageV.image?.size.height ?? 0
        let imageVW:CGFloat = imageV.image?.size.width ?? 0
        let titleH:CGFloat = 16
        let margin:CGFloat = 10
        let x:CGFloat = (frame.size.width - imageVW)/2
        let y:CGFloat = (frame.size.height - imageVH - titleH - margin)/2
        imageV.frame = CGRect(x: x, y: y, width: imageVW, height: imageVH)
        titleLab.frame = CGRect(x: 0, y: imageV.frame.maxY + margin, width: frame.size.width, height: titleH)
        
    }

}
